package com.burgeon.backend.Rest.Tags;
/**
 * 查询标签id通过vid
 */


import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.entity.VipAttrib;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class QueryTagsDataByVip extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public QueryTagsDataByVip(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public VipAttrib getData(String phone) {
        String url = "http://" + ip + "/servlets/binserv/Rest";
        try {
            String str = RESULT(Data(phone), url);
            System.err.println(str);
            String code = new JSONArray(str).getJSONObject(0).getString("code");



            JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
            VipAttrib vipAttrib = new VipAttrib();
            vipAttrib.setVipAttrib1(jsonArray.getJSONArray(0).getString(1));
            vipAttrib.setVipAttrib2(jsonArray.getJSONArray(0).getString(2));
            vipAttrib.setVipAttrib3(jsonArray.getJSONArray(0).getString(3));
            vipAttrib.setVipAttrib4(jsonArray.getJSONArray(0).getString(4));
            vipAttrib.setVipAttrib5(jsonArray.getJSONArray(0).getString(5));
            vipAttrib.setVipAttrib6(jsonArray.getJSONArray(0).getString(6));
            vipAttrib.setVipAttrib7(jsonArray.getJSONArray(0).getString(7));
            vipAttrib.setVipAttrib8(jsonArray.getJSONArray(0).getString(8));
            vipAttrib.setVipAttrib9(jsonArray.getJSONArray(0).getString(9));
            vipAttrib.setVipAttrib10(jsonArray.getJSONArray(0).getString(10));
            vipAttrib.setVipAttrib11(jsonArray.getJSONArray(0).getString(11));
            vipAttrib.setVipAttrib12(jsonArray.getJSONArray(0).getString(12));
            vipAttrib.setVipAttrib13(null);
            vipAttrib.setVipAttrib14(null);
            vipAttrib.setVipAttrib15(null);
            return vipAttrib;
        }catch (Exception e){
            System.err.println("无vip标签");
        }
        return new VipAttrib();
    }

    private MultiValueMap Data(String phone) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        columns.add("ID");
        columns.add("'C_VIPATTRIB1_ID;NAME'");
        columns.add("'C_VIPATTRIB2_ID;NAME'");
        columns.add("'C_VIPATTRIB3_ID;NAME'");
        columns.add("'C_VIPATTRIB4_ID;NAME'");
        columns.add("'C_VIPATTRIB5_ID;NAME'");
        columns.add("'C_VIPATTRIB6_ID;NAME'");
        columns.add("'C_VIPATTRIB7_ID;NAME'");
        columns.add("'C_VIPATTRIB8_ID;NAME'");
        columns.add("'C_VIPATTRIB9_ID;NAME'");
        columns.add("'C_VIPATTRIB10_ID;NAME'");
        columns.add("'C_VIPATTRIB11_ID;NAME'");
        columns.add("'C_VIPATTRIB12_ID;NAME'");

        params.put("columns", columns);
        params.put("table", "C_VIPATTRIB");//表名


        HashMap paramss = new HashMap();
        String ac = "'" + phone + "'";
        paramss.put("column", "'C_VIP_ID;CARDNO'");
        paramss.put("condition", ac);
        params.put("params", paramss);

        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        QueryTagsDataByVip g = new QueryTagsDataByVip("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(g.getData("17732141036"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
